home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7688 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: more problems with qsort
  5. Date: 26 Feb 1996 13:43:35 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gt9i7INN76i@keats.ugrad.cs.ubc.ca>
  8. References: <177399702S86.JW1675A@american.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <177399702S86.JW1675A@american.edu>,
  12. James D. Watson <JW1675A@american.edu> wrote:
  13.  >Hi folks --
  14.  > 
  15.  >after reading the FAQ entries about qsort, I thought I had my problem
  16.  >licked, but it seems not.
  17.  > 
  18.  >Architecture: SunOS 4.1.3 with ANSI-C compiler.
  19.  > 
  20.  >I'm doing some file manipulation and between steps A and B, I need to sort.
  21.  >For various reasons, I don't want to popen() to the sort utility--I want to
  22.  >use qsort.  Here's what I'm doing:
  23.  > 
  24.  >   get number of lines in the file
  25.  >   (char**)malloc with enough room for all lines
  26.  >   for each line in the file {
  27.  >     (char*)malloc(90)  /* 90 is enough room for each line in file */
  28.  >     copy each line into the newly malloc()ed space
  29.  >     point a (char**) to the newly malloc()ed space
  30.  >   }
  31.  > 
  32.  >so now I should have "lines" number of pointers to pointers to char,
  33.  >each one pointing to 90 bytes containing a line in the file.
  34.  > 
  35.  >So, I call qsort(array[0], lines, 90, compare)
  36.  >where compare is my comparison function -- prepared as discussed
  37.  >in the FAQ.  Now all I get are core dumps during the call to qsort().
  38.  >:-)
  39.  
  40. You need a pointer to the first element of the array, not the first element
  41. itself. You should be calling it qsort(array, ... );
  42.  
  43. -- 
  44.  
  45.